from .base import Sort


class Selection(Sort):
    '''选择排序'''

    def name(self):
        return "选择排序"

    def sort(self, data, low=0, hight=0):
        hight = len(data) if hight == 0 else hight
        self.compare_counter = 0
        for i in range(hight):
            target = i
            for j in range(i, hight):
                self.compare_counter += 1
                if self.compare(data[j], data[target], True):
                    target = j
            self.exchange(data, i, target)
